<template>
  <div>
    <div style="marginBottom: 5px">
      <p>
        点击“
        <span style="color : red">选择</span>”按钮，选择要导入的xls文件。
      </p>
    </div>
    <el-upload
      ref="upload"
      class="importPrice"
      action="/api/cms_claimfac/rpPart/importExcel"
      accept=".xlsx, .xls"
      :limit="1"
      :headers="headersObj"
      :on-success="showErrorList"
      :on-exceed="handleExceed"
    >
      <multiuse-button size="small" type="primary" plain>点击上传</multiuse-button>
    </el-upload>
  </div>
</template>
<script>
import { getToken, getAppId, getUserId } from '@/assets/js/auth';
import { downloadModel } from '@/api/claim/factory/AuthPartMaintain';
import { exportExcelFile } from '@/utils';
export default {
  // 获取审批单ID
  data() {
    return {
      headersObj: {
        jwt: getToken(),
        appId: getAppId(),
        userId: getUserId(),
        userAgent: 'pc'
      },
      errorList: [],
      exportLoading: false
    };
  },
  methods: {
    downloadTemplate() {
      this.$confirm('此操作将下载excel模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.exportLoading = true;
        downloadModel().then(res => {
          console.log(res);
          exportExcelFile(res.data, '银行导入模板');
          this.exportLoading = false;
        });
      });
    },
    showErrorList(response, file, fileList) {
      if (response.resultCode === 200) {
        this.$notify.success({ title: '提示信息', message: '导入完成!' });
        this.$emit('importclose');
      } else {
        this.$notify.error({ title: '提示信息', message: response.errMsg });
      }
    },
    handleExceed(files, fileList) {
      this.$message(`只能选择一个文件`);
    }
  }
};
</script>
<style lang="less" scoped></style>>
